
fun (: 'print-all' ( set ) [
  ( 'print-all' delog .)
  const (: 'elements' ( that each ) )
  loop [
    elements next else [ return ( none ) ] delog
  ]
  that
] )

fun (: 'range' ( class [ none param (: 'to' (number) 0 ) param (: 'from' (number) 0 ) ] ) [
  generator (: ( number ) [
    var (: 'index' ( that from ) )
    loop [
      that to > ( index ++ ) else [ stop ] throw
    ]
  ] )
] )

const (: 'fib-set' (
  generator (: ( number ) [
    const (: 'n' 1 )
    var (: 'v0' ) var (: 'v1' 1 ) var (: 'v2' 0 )
    loop [
      ( v2 throw .)
      ( v0 ( v1 !) .)
      ( v1 ( v2 !) .)
      ( v2 ( v0 + ( v1 ) !) .)
    ]
  ] )
) )

fun (: 'getn' ( class [ none param (: 'n' ( number ) 0 ) param (: 'the-set' ( set ) ) ] ) [
  generator (: ( number ) [
    const (: 'i' 0 )
    const (: 'elements' ( that the-set each ) )
    loop [
      ( that n >= ( i ++ ) else [ stop ] .)
      ( elements next else [ stop ] throw .)
    ]
  ] )
] )

fun (: 'ceiling' ( class [ none param (: 'max' ( number ) 0 ) param (: 'the-set' ( set ) ) ] ) [
  generator (: ( number ) [
    const (: 'elements' ( that the-set each ) )
    loop [
      that max > ( elements next else [ stop ] ) then [ elements value throw ]
    ]
  ] )
] )

fun (: 'fib-rec' ( number ) [
  ( that == 0 else [ that == 1 ] then [ return 1 ] .)
  fib-rec ( that - 1 ) + ( fib-rec ( that - 2 ) )
] )

fun (: 'filter' ( class [ none param (: 'the-function' ( function ) ) param (: 'the-set' ( set ) ) ] ) [
  generator (: ( number ) [
    const (: 'elements' ( that the-set each ) )
    loop [
      that the-function ( elements next else [ stop ] ) throw
    ]
  ] )
] )


const (: 'first-100' ( getn (: 100 ( fib-set ) ) ) )

( print-all ( ceiling (: ( 2 pow 52 ) ( first-100 ) ) ) .)

( print-all ( filter (: ( fib-rec ) ( range (: 10 15 ) ) ) ) .)



